package com.imooc.reader.portal.dto;

import com.imooc.reader.portal.service.impl.exception.BusinessException;
import lombok.Data;

import java.util.LinkedHashMap;
import java.util.Map;

@Data
public class ResponseDTO {
    private String code;
    private String message;
    private Map data = new LinkedHashMap();
    public ResponseDTO(){
        this.code = "0";
        this.message = "success";
    }
    public ResponseDTO(String code , String message){
        this.code = code;
        this.message = message;
    }

    public ResponseDTO(Exception e){
        if(e instanceof BusinessException be){
            this.code = be.getCode();
            this.message = be.getMessage();
        }else {
            this.code = e.getClass().getSimpleName();
            this.message = e.getMessage();
        }
    }

    public ResponseDTO put(String key , Object val){
        this.data.put(key,val);
        return this;
    }
}
